package com.lb.jwitter.action;


 import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
 import java.util.List;
import java.util.Date;
import java.util.List;
 import java.util.Map; 
import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import com.opensymphony.xwork2.ActionContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext;
 import com.opensymphony.xwork2.Action; 
 import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.service.TblQLDTTXADMKhoaHoc;
import com.lb.jwitter.service.TblQLDTTXADMKhoaHocService;
 import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuDangKyMonHoc;
 import com.lb.jwitter.service.TblQLDTTXAHocVienPhieuDangKyMonHocService;
 import com.lb.jwitter.service.TblQLDTTXAHocVien;
 import com.lb.jwitter.service.TblQLDTTXAHocVienService;

import com.lb.jwitter.service.TblCanBo;
 import com.lb.jwitter.service.TblCanBoService;

import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNam;
import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNamService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocVienPhieuDangKyMonHocFormAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private List<TblQLDTTXAHocVienPhieuDangKyMonHoc> tblQLDTTXAHocVienPhieuDangKyMonHocs; 
    public List<TblQLDTTXAHocVienPhieuDangKyMonHoc>  getTblQLDTTXAHocVienPhieuDangKyMonHocs() {
         return tblQLDTTXAHocVienPhieuDangKyMonHocs; 
      } 

    private TblQLDTTXAHocVienPhieuDangKyMonHocService tblQLDTTXAHocVienPhieuDangKyMonHocService; 

    private List<TblQLDTTXAHocVien> tblQLDTTXAHocViens; 
    public List<TblQLDTTXAHocVien>  getTblQLDTTXAHocViens(){ 
              return tblQLDTTXAHocViens; 
     } 

    private TblQLDTTXAHocVienService tblQLDTTXAHocVienService; 

    private List<TblCanBo> tblCanBos; 
    public List<TblCanBo>  getTblCanBos(){ 
              return tblCanBos; 
     } 

    private TblCanBoService tblCanBoService; 
    
    private TblQLDTTXAHocKyTrongNam tblQLDTTXAHocKyTrongNam;

    private List<TblQLDTTXAHocKyTrongNam> tblQLDTTXAHocKyTrongNams; 
    public List<TblQLDTTXAHocKyTrongNam>  getTblQLDTTXAHocKyTrongNams(){ 
              return tblQLDTTXAHocKyTrongNams; 
     } 

    private TblQLDTTXAHocKyTrongNamService tblQLDTTXAHocKyTrongNamService; 
    
    private List<TblQLDTTXADMKhoaHoc> tblQLDTTXADMKhoaHocs; 
    public List<TblQLDTTXADMKhoaHoc>  getTblQLDTTXADMKhoaHocs(){ 
              return tblQLDTTXADMKhoaHocs; 
     } 

    private TblQLDTTXADMKhoaHocService tblQLDTTXADMKhoaHocService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HocVien_PhieuDangKyMonHoc", "xem")){ 
        return "noprivilege"; 
    }
    tblQLDTTXAHocVienPhieuDangKyMonHocService = (TblQLDTTXAHocVienPhieuDangKyMonHocService) context.getBean("tbl_QLDTTXA_HocVien_PhieuDangKyMonHocClient"); 
         tblQLDTTXAHocVienService = (TblQLDTTXAHocVienService) context.getBean("tbl_QLDTTXA_HocVienClient"); 

        tblCanBoService = (TblCanBoService) context.getBean("tbl_CanBoClient"); 

        tblQLDTTXAHocKyTrongNamService = (TblQLDTTXAHocKyTrongNamService) context.getBean("tbl_QLDTTXA_HocKyTrongNamClient"); 
        tblQLDTTXADMKhoaHocService = (TblQLDTTXADMKhoaHocService) context.getBean("tbl_QLDTTXA_DM_KhoaHocClient"); 

       if(pageSize == 0){ 
            pageSize = 20; 
        } 
        if(page == 0){ 
            page =1; 
        } 
        

        Date today = new Date();
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
        if(true){
        	DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
        	ConditionReport con = new ConditionReport(); 
            con.setCol("thoiGianBatDau");
            con.setValue1(df.format(today));
            con.setOperator("le");
            con.setType("date");
            cons.add(con);	
            
            ConditionReport con2 = new ConditionReport(); 
            con2.setCol("thoiGianKetThuc");
            con2.setValue1(df.format(today));
            con2.setOperator("ge");
            con2.setType("date");
            cons.add(con2);	           
            	
        }
        tblQLDTTXAHocKyTrongNams = tblQLDTTXAHocKyTrongNamService.findtblQLDTTXAHocKyTrongNamByCondition(cons, 0, 0);
        tblQLDTTXADMKhoaHocs = tblQLDTTXADMKhoaHocService.findAlltblQLDTTXADMKhoaHoc(0, 0);

        if(tblQLDTTXAHocKyTrongNams != null && tblQLDTTXAHocKyTrongNams.size() > 0){
        	tblQLDTTXAHocKyTrongNam = tblQLDTTXAHocKyTrongNams.get(0);
        }
        
        cons.clear();
        if(tblQLDTTXAHocKyTrongNam != null){
        	ConditionReport con = new ConditionReport(); 
            con.setCol("hocKyId.id");
            con.setValue1(tblQLDTTXAHocKyTrongNam.getId());
            con.setOperator("eq");
            cons.add(con);	
            
        }else{
        	ConditionReport con = new ConditionReport(); 
            con.setCol("hocKyId.id");
            con.setValue1(new Long(1));
            con.setOperator("eq");
            cons.add(con);	
        }
        tblQLDTTXAHocVienPhieuDangKyMonHocs = tblQLDTTXAHocVienPhieuDangKyMonHocService.findtblQLDTTXAHocVienPhieuDangKyMonHocByCondition(cons, pageSize, page); 
        pages = tblQLDTTXAHocVienPhieuDangKyMonHocService.counttblQLDTTXAHocVienPhieuDangKyMonHocByCondition(cons)/pageSize + 1;
        

        cons.clear();
        {
        	ConditionReport con3 = new ConditionReport(); 
            con3.setCol("id");
            con3.setValue1("desc");
            con3.setOperator("order");
            cons.add(con3);        	
        }
      tblQLDTTXAHocKyTrongNams = tblQLDTTXAHocKyTrongNamService.findtblQLDTTXAHocKyTrongNamByCondition(cons, 0, 0);
      dataString = ""; 
      dataString += "&hocVienId=" ; 
      dataString += "&tungayNop="; 
      dataString += "&denngayNop="; 
      if(tblQLDTTXAHocKyTrongNam != null)
    	  dataString += "&hocKyId="+tblQLDTTXAHocKyTrongNam.getId() ; 
      else
    	  dataString += "&hocKyId=1" ; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi Form tbl_QLDTTXA_HocVien_PhieuDangKyMonHoc Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 }

public TblQLDTTXAHocKyTrongNam getTblQLDTTXAHocKyTrongNam() {
	return tblQLDTTXAHocKyTrongNam;
}

public void setTblQLDTTXAHocKyTrongNam(
		TblQLDTTXAHocKyTrongNam tblQLDTTXAHocKyTrongNam) {
	this.tblQLDTTXAHocKyTrongNam = tblQLDTTXAHocKyTrongNam;
} 
 } 
 
